//
//  YMAnimationView.swift
//  YMSwiftUI
//
//  Created by anscen on 2022/6/21.
//

import SwiftUI

struct YMAnimationView: View {
    @State var animation = false
    @State var startAnimation = false
    var body: some View {
        VStack.init {
            Demo4()
            Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/).onTapGesture {
                startAnimation.toggle()
            }.background(Color.red).offset(x: animation ? 100 : -100,y:animation ? 100 : -100).animation(.easeInOut(duration: 0.35), value: animation)
            
            Text("Hello world")
               .animation(.linear(duration: 0.3), value: startAnimation)
               .opacity(startAnimation ? 0 : 1)
        }.navigationTitle("动画").navigationBarItems(leading: BaseNavigationBarBackButton()).navigationBarBackButtonHidden(true)
    }
}
struct Demo4: View {
   @State var x: CGFloat = 0
   @State var y: CGFloat = 0
   var body: some View {//
       VStack {
           Spacer()
           Circle().fill(.orange).frame(width: 30, height: 30).offset(x: x, y: y) // x、y 分别关联了不同的时序曲线函数
           Spacer()
           Button("Animate") {
               withAnimation(.linear) {
                   if x == 0 { x = 100 } else { x = 0 }
               }
               withAnimation(.easeInOut) {
                   if y == 0 { y = 100 } else { y = 0 }
               }
           }
       }.frame(width: 500, height: 500)
   }
}
//struct YMAnimationView_Previews: PreviewProvider {
//    static var previews: some View {
//        YMAnimationView()
//    }
//}
